package yl.hs.bmipfull.controllers.report;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;
import yl.hs.bmipfull.controllers.ControllerBase;
import yl.hs.bmipfull.service.report.ISalesStatisticService;
import yl.hs.bmipfull.viewmodels.PageQuery;
import yl.hs.bmipfull.viewmodels.WebResult;

import java.util.ArrayList;

/**
 * @author 张凯
 * @apiNote 销售统计Controller
 * @since 2022/2/22 9:05 上午 创建
 */
@Api(value = "销售报表Web接口", tags = "报表中心——销售报表Web")
@RequestMapping(value = "/api/report/sales")
@RestController
public class SalesStatisticController extends ControllerBase {


    final
    ISalesStatisticService service;

    public SalesStatisticController(ISalesStatisticService service) {
        this.service = service;
    }

    @ApiOperation(value = "产品分析报表", notes = "产品分析报表")
    @RequestMapping(value = "/productAnalysis/{productCateSn}", method = RequestMethod.POST)
    public WebResult productSaleReport(@ApiParam(value = "查询条件") @RequestBody PageQuery pageQuery,@ApiParam(value = "发货单类型") @PathVariable String productCateSn) {
        try {
            return success("查询成功", service.productSaleReport(pageQuery,productCateSn));
        } catch (Exception e) {
            return error(e);
        }
    }


    @ApiOperation(value = "工程分析报表", notes = "工程分析报表")
    @RequestMapping(value = "/project/statistic/{productCateSn}", method = RequestMethod.POST)
    public WebResult queryProjectStatistic(@ApiParam(value = "查询条件") @RequestBody PageQuery pageQuery,@ApiParam(value = "发货单类型") @PathVariable String productCateSn) {
        try {
            return success("查询成功", service.queryProjectStatistic(pageQuery,productCateSn));
        } catch (Exception e) {
            return error(e);
        }
    }

    @ApiOperation(value = "查询客户发货分析", notes = "查询客户发货分析")
    @RequestMapping(value = "/customer/{productCateSn}",method = RequestMethod.POST)
    public WebResult getCustomerAnalysis(@ApiParam(value = "查询条件") @RequestBody PageQuery pageQuery,
                                         @ApiParam(value = "发货单类型") @PathVariable String productCateSn){
        var result =  service.queryCustomerAnalysis(pageQuery,productCateSn);
        if(result==null){
            return  success("无数据",new ArrayList<>());
        }
        return success("查询成功",result);
    }


    @ApiOperation(value = "车辆分析报表", notes = "车辆分析报表")
    @RequestMapping(value = "/truck/statistic/{productCateSn}", method = RequestMethod.POST)
    public WebResult queryCarSaleReport(@ApiParam(value = "查询条件") @RequestBody PageQuery pageQuery,@ApiParam(value = "发货单类型") @PathVariable String productCateSn) {
        try {
            return success("查询成功", service.queryTruckSaleReport(pageQuery,productCateSn));
        } catch (Exception e) {
            return error(e);
        }
    }

    @ApiOperation(value = "加气块查询客户发货分析", notes = "查询客户发货分析")
    @RequestMapping(value = "/brickCustomerStatistics",method = RequestMethod.POST)
    public WebResult brickCustomerStatistics(@ApiParam(value = "查询条件") @RequestBody PageQuery pageQuery
    ){
        var result =  service.queryBrickCustomerAnalysis(pageQuery);
        if(result==null){
            return  success("无数据",new ArrayList<>());
        }
        return success("查询成功",result);
    }
    @ApiOperation(value = "加气块查询产品发货分析", notes = "查询客户发货分析")
    @RequestMapping(value = "/brickProductStatistics",method = RequestMethod.POST)
    public WebResult brickProductStatistics(@ApiParam(value = "查询条件") @RequestBody PageQuery pageQuery
    ){
        var result =  service.queryBrickProductAnalysis(pageQuery);
        if(result==null){
            return  success("无数据",new ArrayList<>());
        }
        return success("查询成功",result);
    }
}
